using System.Configuration;

using Common;

using GRPCDemo.Network;
using GRPCDemo.Services;


namespace GRPCDemo
{
    public class Server
    {
        NetService? network;

        public void Init()
        {
            string ip = ConfigurationManager.AppSettings["Ip"] ?? "127.0.0.1";
            string portStr = ConfigurationManager.AppSettings["Port"] ?? "8000";
            int.TryParse(portStr, out int port);

            network = new NetService(ip, port, 10);
            DBService.Instance.Init();
        }

        public void Start()
        {
            network?.Start();
            UserService.Instance.Start();
            LicenseService.Instance.Start();
            Log.Info($"The Server is Running at {network.address}:{network.port}");
        }

        public void Stop()
        {
            network?.Stop();
            UserService.Instance.Stop();
            LicenseService.Instance.Stop();
        }
    }
}
